package com.dkcd.chenshiproject.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView.ViewHolder;

import com.dkcd.chenshiproject.R;
import com.dkcd.chenshiproject.entity.Song;

import org.w3c.dom.Text;

import java.util.List;
import java.util.Map;

/**
 * com.dkcd.chenshiproject.adapter 新建一个类
 *
 * @author ChenShi
 * @version：1.0
 * @date 2022/6/15
 */
public class ReCommendMusicAdapter extends BaseAdapter {
    private Context context;
    private List<Map<String, Object>> list;

    public ReCommendMusicAdapter(Context context, List<Map<String, Object>> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        RecommendHolder holder = null;
        if (view == null){
            holder = new RecommendHolder();
             view = View.inflate(context, R.layout.re_commend_grid_view_item, null);

             holder.imgItemImages = (ImageView) view.findViewById(R.id.img_item_images);
             holder.reCommendItemTitle = (TextView) view.findViewById(R.id.re_commend_item_title);

            view.setTag(holder);
        }else {
            holder = (RecommendHolder) view.getTag();
        }

        //赋值
        holder.reCommendItemTitle.setText((String)list.get(i).get("title"));
        holder.imgItemImages.setImageBitmap((Bitmap)list.get(i).get("img"));

        return view;
    }

    class RecommendHolder{
        ImageView imgItemImages;
        TextView reCommendItemTitle;
    }
}
